<template>
    <div class="sidebar">
        <el-menu
            class="sidebar-el-menu"
            :default-active="onRoutes"
            :collapse="collapse"
            background-color="#324157"
            text-color="#bfcbd9"
            active-text-color="#20a0ff"
            unique-opened
            router
        >
            <template v-for="item in items">
                <template v-if="item.subs">
                    <el-submenu :index="item.index" :key="item.index">
                        <template slot="title">
                            <i :class="item.icon"></i>
                            <span slot="title">{{ item.title }}</span>
                        </template>
                        <template v-for="subItem in item.subs">
                            <el-submenu v-if="subItem.subs" :index="subItem.index" :key="subItem.index">
                                <template slot="title">{{ subItem.title }}</template>
                                <template v-for="thItem in subItem.subs">
                                    <el-submenu v-if="thItem.subs" :index="thItem.index" :key="thItem.index">
                                        <template slot="title">{{ thItem.title }}</template>
                                        <el-menu-item v-for="(threeItem, i) in thItem.subs" :key="i" :index="threeItem.index"
                                            >{{ threeItem.title }}
                                        </el-menu-item>
                                    </el-submenu>
                                    <el-menu-item v-else :index="thItem.index" :key="thItem.index">{{ thItem.title }} </el-menu-item>
                                </template>
                            </el-submenu>
                            <el-menu-item v-else :index="subItem.index" :key="subItem.index">{{ subItem.title }}</el-menu-item>
                        </template>
                    </el-submenu>
                </template>
                <template v-else>
                    <el-menu-item :index="item.index" :key="item.index">
                        <i :class="item.icon"></i>
                        <span slot="title">{{ item.title }}</span>
                    </el-menu-item>
                </template>
            </template>
        </el-menu>
    </div>
</template>

<script>
import bus from '../common/bus';
export default {
    data() {
        return {
            collapse: false,
            items: [
                {
                    icon: 'el-icon-lx-home',
                    index: 'dashboard',
                    title: '系统首页'
                },
                {
                    icon: 'el-icon-menu',
                    index: '1',
                    title: '我发起的',
                    subs: [
                        {
                            index: '1-1',
                            title: '图纸会审',
                            subs: [
                                {
                                    index: 'upload_drawing',
                                    title: '上传图纸'
                                },
                                {
                                    index: 'import_drawing',
                                    title: '导入图纸'
                                }
                            ]
                        },
                        {
                            index: '1-2',
                            title: '工程变更',
                            subs: [
                                {
                                    index: 'new_application_form',
                                    title: '新建工程设计变更申请单'
                                },
                                {
                                    index: 'work_order',
                                    title: '编制工程设计变更通知单'
                                },
                                {
                                    index: 'prepare_change_sheet',
                                    title: '编制工程变更单'
                                },
                                {
                                    index: 'prepare_instruction_sheet',
                                    title: '编制工程变更指令确认单'
                                },
                                {
                                    index: 'prepare_settlement',
                                    title: '编制工程变更签证结算书说明'
                                }
                            ]
                        },
                        {
                            index: '1-3',
                            title: '质量控制'
                        },
                        {
                            index: '1-4',
                            title: '成本控制'
                        },
                        {
                            index: '1-5',
                            title: '进度控制'
                        },
                        {
                            index: '1-6',
                            title: '安全管理'
                        },
                        {
                            index: '1-7',
                            title: '合同管理'
                        }
                    ]
                },
                {
                    icon: 'el-icon-time',
                    index: '2',
                    title: '我审批的',
                    subs: [
                        {
                            index: '2-1',
                            title: '图纸会审',
                            subs: [
                                {
                                    index: 'drawing_examine',
                                    title: '图纸批注'
                                },
                                {
                                    index: 'other_function',
                                    title: '模型批注'
                                },
                                {
                                    index: 'answer_questions',
                                    title: '答疑'
                                },
                                {
                                    index: 'examine_conclusion',
                                    title: '会审结论'
                                }
                            ]
                        },
                        {
                            index: '2-2',
                            title: '工程变更',
                            subs: [
                                {
                                    index: '2-2-1',
                                    title: '图模操作',
                                    subs: [
                                        {
                                            index: 'drawing_upload',
                                            title: '图模上传'
                                        },
                                        {
                                            index: 'drawing_import',
                                            title: '图模导入'
                                        },
                                        {
                                            index: 'drawing_compare',
                                            title: '图纸对比'
                                        },
                                        {
                                            index: 'model_compare',
                                            title: '模型对比'
                                        }
                                    ]
                                },
                                {
                                    index: 'watcher_examine',
                                    title: '监理审批'
                                },
                                {
                                    index: 'boss_examine',
                                    title: '业主审批'
                                },
                                {
                                    index: 'designer_examine',
                                    title: '设计方审批'
                                },
                                {
                                    index: 'money_cal',
                                    title: '成本结果估算'
                                }
                            ]
                        },
                        {
                            index: '2-3',
                            title: '质量控制'
                        },
                        {
                            index: '2-4',
                            title: '成本控制'
                        },
                        {
                            index: '2-5',
                            title: '进度控制'
                        },
                        {
                            index: '2-6',
                            title: '安全管理'
                        },
                        {
                            index: '2-7',
                            title: '合同管理'
                        }
                    ]
                },
                {
                    icon: 'el-icon-lx-calendar',
                    index: '3',
                    title: '我的待办',
                    subs: [
                        {
                            index: '3-1',
                            title: '图纸会审',
                            subs: [
                                {
                                    index: 'result_set',
                                    title: '会审结论记录表  '
                                }
                            ]
                        },
                        {
                            index: '3-2',
                            title: '工程变更',
                            subs: [
                                {
                                    index: 'check_notification',
                                    title: '查看通知'
                                },
                                {
                                    index: 'check_change_sheet',
                                    title: '查收工程变更单'
                                }
                            ]
                        },
                        {
                            index: '3-3',
                            title: '质量控制'
                        },
                        {
                            index: '3-4',
                            title: '成本控制'
                        },
                        {
                            index: '3-5',
                            title: '进度控制'
                        },
                        {
                            index: '3-6',
                            title: '安全管理'
                        },
                        {
                            index: '3-7',
                            title: '合同管理'
                        }
                    ]
                },
                {
                    icon: 'el-icon-chat-dot-round',
                    index: 'info',
                    title: '信息中心'
                }
            ]
        };
    },
    computed: {
        onRoutes() {
            return this.$route.path.replace('/', '');
        }
    },
    created() {
        // 通过 Event Bus 进行组件间通信，来折叠侧边栏
        bus.$on('collapse', msg => {
            this.collapse = msg;
            bus.$emit('collapse-content', msg);
        });
    }
};
</script>

<style scoped>
.sidebar {
    display: block;
    position: absolute;
    left: 0;
    top: 70px;
    bottom: 0;
    overflow-y: scroll;
}
.sidebar::-webkit-scrollbar {
    width: 0;
}
.sidebar-el-menu:not(.el-menu--collapse) {
    width: 250px;
}
.sidebar > ul {
    height: 100%;
}
</style>
